/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Random;

/**
 * <p>Project: app2022 - ArrSort1
 * <p>Powered by webrx On 2022-01-08 16:26:29
 *
* @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ArrSort1 {
    public static void main(String[] args) {
        var rand = new Random();
        //int基本类型 Integer是int基本的类型的包装器类型
        var nums = new Integer[10];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = rand.nextInt(100) + 1;
        }

        System.out.println(Arrays.toString(nums));
        //升序
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));

        //降序
        //Arrays.sort(nums, (a, b) ->a - b); 升序
        Arrays.sort(nums, (a, b) -> b - a);
        System.out.println(Arrays.toString(nums));

        //乱序 (a,b)-> lambda 表达式
        //Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? 1 : -1);
        Arrays.sort(nums, (a, b) -> rand.nextDouble() > .5 ? 1 : -1);
        Arrays.sort(nums, (a, b) -> rand.nextDouble() > .5 ? 1 : -1);
        Arrays.sort(nums, (a, b) -> rand.nextDouble() > .5 ? 1 : -1);

        System.out.println(Arrays.toString(nums));


    }
}
